home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -seriously_amiga- / shareware / programming / other / apic / examples / dimmer.lst < prev    next >
File List  |  1998-01-05  |  20KB  |  403 lines

  1. #PIC V1.0 (c)1997 J.Petroglou    LIST FILE
  2. #file: dh2:IDE/APICforAMINET/APIC/examples/dimmer.asm
  3. #date: Sun Dec 14 20:42:11 1997
  4. #pic : PIC16C84
  5. #xtal: 4000000 Hz
  6.  
  7. ADDR CODE     SRCLINE SOURCECODE
  8.  
  9. 0000             000001 
  10. 0000             000002 ;
  11. 0000             000003 ; pic 4 dummies..
  12. 0000             000004 ; This is a phase first slicer for the 16C84 - documented in broken inglisch ;-(
  13. 0000             000005 ; assemble me with: picasm dimm.asm <CR>
  14. 0000             000006 ; $VER: dimmer.asm V1.42 (19.09.97)
  15. 0000             000007 ; ©: This program is free software and can be used and distributed
  16. 0000             000008 ; ©: under the terms of the GNU General Public License.
  17. 0000             000009 ;
  18. 0000             000010 
  19. 0000             000011 
  20. 0000             000012   list  p=PIC16C84, r=dec, s=on
  21. 0000             000013 ;                          ^interpret the code as case sensItive
  22. 0000             000014 ;                   ^radix is decimal
  23. 0000             000015 ;       ^the `84 is the target processor
  24. 0000             000016 
  25. 0000             000017 
  26. 0000             000018 
  27. 0000             000019   device hs_osc,protect_off,wdt_off
  28. 0000             000020 ;                           ^the watchdog sleeps ;-)
  29. 0000             000021 ;               ^no read protection
  30. 0000             000022 ;        ^config the osilator in high-speed mode
  31. 0000             000023 
  32. 0000             000024 
  33. 0000             000025 
  34. 0000             000026   XTAL 4000000 ;crystal freq. for Amiga Picsim [Hz]
  35. 0000             000027 
  36.  
  37. #include 'ram:p16c84.inc' start
  38. 0000             000001 ;==========================================================================
  39. 0000             000002 ;
  40. 0000             000003 ;       Register Definitions
  41. 0000             000004 ;
  42. 0000             000005 ;==========================================================================
  43. 0000             000006 
  44. 0000             000007 W                            EQU     H'0000'
  45. 0000             000008 F                            EQU     H'0001'
  46. 0000             000009 
  47. 0000             000010 ;----- Register Files------------------------------------------------------
  48. 0000             000011 
  49. 0000             000012 INDF                         EQU     H'0000'
  50. 0000             000013 TMR0                         EQU     H'0001'
  51. 0000             000014 PCL                          EQU     H'0002'
  52. 0000             000015 STATUS                       EQU     H'0003'
  53. 0000             000016 FSR                          EQU     H'0004'
  54. 0000             000017 PORTA                        EQU     H'0005'
  55. 0000             000018 PORTB                        EQU     H'0006'
  56. 0000             000019 EEDATA                       EQU     H'0008'
  57. 0000             000020 EEADR                        EQU     H'0009'
  58. 0000             000021 PCLATH                       EQU     H'000A'
  59. 0000             000022 INTCON                       EQU     H'000B'
  60. 0000             000023 
  61. 0000             000024 OPTION_REG                   EQU     H'0081'
  62. 0000             000025 TRISA                        EQU     H'0085'
  63. 0000             000026 TRISB                        EQU     H'0086'
  64. 0000             000027 EECON1                       EQU     H'0088'
  65. 0000             000028 EECON2                       EQU     H'0089'
  66. 0000             000029 
  67. 0000             000030 ;----- STATUS Bits --------------------------------------------------------
  68. 0000             000031 
  69. 0000             000032 IRP                          EQU     H'0007'
  70. 0000             000033 RP1                          EQU     H'0006'
  71. 0000             000034 RP0                          EQU     H'0005'
  72. 0000             000035 NOT_TO                       EQU     H'0004'
  73. 0000             000036 NOT_PD                       EQU     H'0003'
  74. 0000             000037 Z                            EQU     H'0002'
  75. 0000             000038 DC                           EQU     H'0001'
  76. 0000             000039 C                            EQU     H'0000'
  77. 0000             000040 
  78. 0000             000041 ;----- INTCON Bits --------------------------------------------------------
  79. 0000             000042 
  80. 0000             000043 GIE                          EQU     H'0007'
  81. 0000             000044 EEIE                         EQU     H'0006'
  82. 0000             000045 T0IE                         EQU     H'0005'
  83. 0000             000046 INTE                         EQU     H'0004'
  84. 0000             000047 RBIE                         EQU     H'0003'
  85. 0000             000048 T0IF                         EQU     H'0002'
  86. 0000             000049 INTF                         EQU     H'0001'
  87. 0000             000050 RBIF                         EQU     H'0000'
  88. 0000             000051 
  89. 0000             000052 ;----- OPTION Bits --------------------------------------------------------
  90. 0000             000053 
  91. 0000             000054 NOT_RBPU                     EQU     H'0007'
  92. 0000             000055 INTEDG                       EQU     H'0006'
  93. 0000             000056 T0CS                         EQU     H'0005'
  94. 0000             000057 T0SE                         EQU     H'0004'
  95. 0000             000058 PSA                          EQU     H'0003'
  96. 0000             000059 PS2                          EQU     H'0002'
  97. 0000             000060 PS1                          EQU     H'0001'
  98. 0000             000061 PS0                          EQU     H'0000'
  99. 0000             000062 
  100. 0000             000063 ;----- EECON1 Bits --------------------------------------------------------
  101. 0000             000064 
  102. 0000             000065 EEIF                         EQU     H'0004'
  103. 0000             000066 WRERR                        EQU     H'0003'
  104. 0000             000067 WREN                         EQU     H'0002'
  105. 0000             000068 WR                           EQU     H'0001'
  106. 0000             000069 RD                           EQU     H'0000'
  107. 0000             000070 
  108. 0000             000071 ;==========================================================================
  109. 0000             000072 ;
  110. 0000             000073 ;       RAM Definition
  111. 0000             000074 ;
  112. 0000             000075 ;==========================================================================
  113. 0000             000076 
  114. 0000             000077 ;        __MAXRAM H'AF'
  115. 0000             000078 ;        __BADRAM H'07', H'30'-H'7F', H'87'
  116. 0000             000079 
  117. 0000             000080 ;==========================================================================
  118. 0000             000081 ;
  119. 0000             000082 ;       Configuration Bits
  120. 0000             000083 ;
  121. 0000             000084 ;==========================================================================
  122. 0000             000085 
  123. 0000             000086 _CP_ON                       EQU     H'3FEF'
  124. 0000             000087 _CP_OFF                      EQU     H'3FFF'
  125. 0000             000088 _PWRTE_ON                    EQU     H'3FFF'
  126. 0000             000089 _PWRTE_OFF                   EQU     H'3FF7'
  127. 0000             000090 _WDT_ON                      EQU     H'3FFF'
  128. 0000             000091 _WDT_OFF                     EQU     H'3FFB'
  129. 0000             000092 _LP_OSC                      EQU     H'3FFC'
  130. 0000             000093 _XT_OSC                      EQU     H'3FFD'
  131. 0000             000094 _HS_OSC                      EQU     H'3FFE'
  132. 0000             000095 _RC_OSC                      EQU     H'3FFF'
  133. 0000             000096 
  134. 0000             000097         LIST
  135. #include end.
  136.  
  137. 0000             000029 
  138. 0000             000030 
  139. 0000             000031 ;some definitions ...
  140. 0000             000032 
  141. 0000             000033 #define ELR PORTA,2 ; led-triac modul (via 470R)
  142. 0000             000034 #define POWER_LINE PORTA,3     ; 100V - 250V AC (via 2 * 4M7 in series !)
  143. 0000             000035                                ;    W A R N I N G !¡! HIGH VOLTAGE !!!
  144. 0000             000036 
  145. 0000             000037 
  146. 0000             000038 #define DARKER  PORTB,4       ; connect this pin to ground to make it darker
  147. 0000             000039 #define BRIGHTER  PORTB,5     ; connect this pin to ground to make it brighter
  148. 0000             000040 
  149. 0000             000041 ; these are the definitions work in  MY circuit (230V 50Hz)
  150. 0000             000042 
  151. 0000             000043 #define IGNITION_DELAY 30     ; the led of the power modul must be on for at least
  152. 0000             000044                               ; some µ seconds
  153. 0000             000045 #define IGNITION_PRESET 128     ; about 90° first slice
  154. 0000             000046 #define DIMM_MIN 15          ;max.  value off the fileregister dimm
  155. 0000             000047 
  156. 0000             000048 
  157. 0000             000049 DIMM_MAX     =  200       ; min.  value off the fileregister dimm
  158. 0000             000050 DIMM_X         =  254       ; min.  value off the fileregister dimm
  159. 0000             000051 
  160. 0000             000052 XTAL         = 4000000     ;crystal freq. for delay-time calulations [Hz]
  161. 0000             000053 LINE_FREQ     = 50         ;power_line freq. [Hz]
  162. 0000             000054 
  163. 0000             000055 CLOCKCYCLES_PER_INSTRUCTIONS = 4
  164. 0000             000056 
  165. 0000             000057 IPHW         = XTAL/CLOCKCYCLES_PER_INSTRUCTIONS/LINE_FREQ/2
  166. 0000             000058 
  167. 0000             000059 ; IPHW     = Instruction Per HalvWave( i.e. 10ms @ 50Hz)
  168. 0000             000060 
  169. 0000             000061 
  170. 0000             000062 INSTRUCTIONCYCLES_PER_DELAYCYC = 3
  171. 0000             000063 
  172. 0000             000064 ;DIMM_WAIT     = ((IPHW-50)/DIMM_MAX+20)/ INSTRUCTIONCYCLES_PER_DELAYCYC
  173. 0000             000065 DIMM_WAIT     = (IPHW-122-DIMM_X*8)/ (INSTRUCTIONCYCLES_PER_DELAYCYC * DIMM_X)
  174. 0000             000066 
  175. 0000             000067 
  176. 0000             000068 ; some very simple macros..
  177. 0000             000069 
  178. 0000             000070     macro elr_off
  179. 0000             000071             bcf ELR ; LED of the powermodul off
  180. 0000             000072     endm
  181. 0000             000073 
  182. 0000             000074     macro elr_on
  183. 0000             000075             bsf ELR ; LED of the powermodul on
  184. 0000             000076     endm
  185. 0000             000077 
  186. 0000             000078 
  187. 0000             000080   CBLOCK  0xc
  188. 0000             000081   dimm
  189. 0000             000082   dimm_counter
  190. 0000             000083   wait_counter
  191. 0000             000084   ENDC
  192. 0000             000085 
  193. 0000             000086 
  194. 0000             000087 
  195. 0000             000088   org 0x0 ; the program starts at 0x0000
  196. 0000             000089 
  197. 0000             000091 
  198. 0000 0185        000092             clrf PORTA         ; clear both ports
  199. 0001 0186        000093             clrf PORTB
  200. 0002             000094 
  201. 0002 1683        000095             bsf STATUS, RP0       ; switch to bank 1
  202. 0003             000096 
  203. 0003 1381        000097             bcf OPTION_REG, 7         ; PORTB pull-ups are enabled (for the 2 keys)
  204. 0004             000099 
  205. 0004 3000        000100             movlw 0x0
  206. 0005 0086        000101             movwf TRISB
  207. 0006 0085        000102             movwf TRISA
  208. 0007 1585        000104             bsf POWER_LINE        ; these pins are inputs (in=1, out=0)
  209. 0008 1606        000105             bsf DARKER
  210. 0009 1686        000106             bsf BRIGHTER
  211. 000A             000107 
  212. 000A 1283        000108             bcf STATUS, RP0       ; switch back to bank 0
  213. 000B             000109 
  214. 000B             000110 
  215. 000B 3080        000111             movlw IGNITION_PRESET
  216. 000C 008C        000112             movwf dimm
  217. 000D             000113 
  218. 000D             000114 
  219. 000D             000115 main_loop
  220. 000D 2030        000116             call wait_line_change  ; call a subroutine
  221. 000E 080C        000117             movf dimm,w      ; transfer the the data form the "dimm" file-register
  222. 000F 201D        000119             call dimm_it
  223. 0010 1E86        000120             btfss BRIGHTER     ; test if the BRIGHTER pin is low
  224. 0011 0A8C        000121               incf dimm     ; ok, it`s low, increment dimm by one
  225. 0012 1E06        000122             btfss DARKER       ; test if the DARKER pin is low
  226. 0013 038C        000123               decf dimm     ; ok, it`s low, decrement dimm by one
  227. 0014             000124 
  228. 0014 300F        000125             movlw DIMM_MIN     ; move DIMM_MIN in the working register
  229. 0015 020C        000126             subwf dimm,w      ; subtract w from dimm and store the result in w
  230. 0016 1903        000127             btfsc STATUS, Z     ; is last result Zero ?
  231. 0017 0A8C        000128               incf dimm       ; yes -> inc. dimm
  232. 0018             000129 
  233. 0018 30C8        000130             movlw DIMM_MAX     ; same with the upper limit...
  234. 0019 020C        000131             subwf dimm,w
  235. 001A 1903        000132             btfsc STATUS, Z
  236. 001B 038C        000133               decf dimm     ; ...but here we decrease dimm
  237. 001C             000134 
  238. 001C 280D        000135             goto main_loop     ; jump to main_loop and repeat this stuff forever...
  239. 001D             000136 
  240. 001D             000137 
  241. 001D             000138 dimm_it
  242. 001D 008D        000139             movwf dimm_counter   ; copy w in dimm_counter
  243. 001E 098D        000140             comf dimm_counter,f   ; generate the complement of dimm_counter and
  244. 001F             000142 dimm_loop
  245. 001F 2026        000143             call wait
  246. 0020 0B8D        000144             decfsz dimm_counter
  247. 0021 281F        000145               goto dimm_loop
  248. 0022 1505        000146             bsf ELR ; LED of the powermodul on
  249. 0023 202B        000147             call ignition_wait    ; wait some µ seconds
  250. 0024 1105        000148             bcf ELR ; LED of the powermodul off
  251. 0025 0008        000149             return
  252. 0026             000150 
  253. 0026 300A        000152             movlw DIMM_WAIT
  254. 0027 008E        000153             movwf wait_counter
  255. 0028             000154 wait_loop
  256. 0028 0B8E        000155             decfsz wait_counter
  257. 0029 2828        000156               goto wait_loop
  258. 002A 0008        000157             return
  259. 002B             000158 
  260. 002B             000159 
  261. 002B 301E        000161             movlw IGNITION_DELAY
  262. 002C 008E        000162             movwf wait_counter
  263. 002D             000163 i_wait_loop
  264. 002D 0B8E        000164             decfsz wait_counter
  265. 002E 282D        000165               goto i_wait_loop
  266. 002F 0008        000166             return
  267. 0030             000167 
  268. 0030             000168 
  269. 0030 1D85        000170             btfss POWER_LINE
  270. 0031 2835        000171               goto line_is_low
  271. 0032             000172 line_is_high
  272. 0032 1985        000173             btfsc POWER_LINE
  273. 0033 2832        000174               goto line_is_high
  274. 0034 0008        000175             return         ;return from subroutine
  275. 0035             000176 line_is_low
  276. 0035 1D85        000177             btfss POWER_LINE
  277. 0036 2835        000178               goto line_is_low
  278. 0037 0008        000179             return
  279. 0038             000180 
  280. 0038             000181 
  281. 0038             000182 
  282. 0038             000233 
  283. 0038             000234 
  284.  
  285.  
  286. Used Symbols
  287. -----------------------------------------
  288. W                                00000000
  289. F                                00000001
  290. INDF                             00000000
  291. TMR0                             00000001
  292. PCL                              00000002
  293. STATUS                           00000003
  294. FSR                              00000004
  295. PORTA                            00000005
  296. PORTB                            00000006
  297. EEDATA                           00000008
  298. EEADR                            00000009
  299. PCLATH                           0000000A
  300. INTCON                           0000000B
  301. OPTION_REG                       00000081
  302. TRISA                            00000085
  303. TRISB                            00000086
  304. EECON1                           00000088
  305. EECON2                           00000089
  306. IRP                              00000007
  307. RP1                              00000006
  308. RP0                              00000005
  309. NOT_TO                           00000004
  310. NOT_PD                           00000003
  311. Z                                00000002
  312. DC                               00000001
  313. C                                00000000
  314. GIE                              00000007
  315. EEIE                             00000006
  316. T0IE                             00000005
  317. INTE                             00000004
  318. RBIE                             00000003
  319. T0IF                             00000002
  320. INTF                             00000001
  321. RBIF                             00000000
  322. NOT_RBPU                         00000007
  323. INTEDG                           00000006
  324. T0CS                             00000005
  325. T0SE                             00000004
  326. PSA                              00000003
  327. PS2                              00000002
  328. PS1                              00000001
  329. PS0                              00000000
  330. EEIF                             00000004
  331. WRERR                            00000003
  332. WREN                             00000002
  333. WR                               00000001
  334. RD                               00000000
  335. _CP_ON                           00003FEF
  336. _CP_OFF                          00003FFF
  337. _PWRTE_ON                        00003FFF
  338. _PWRTE_OFF                       00003FF7
  339. _WDT_ON                          00003FFF
  340. _WDT_OFF                         00003FFB
  341. _LP_OSC                          00003FFC
  342. _XT_OSC                          00003FFD
  343. _HS_OSC                          00003FFE
  344. _RC_OSC                          00003FFF
  345. DIMM_MAX                         000000C8
  346. DIMM_X                           000000FE
  347. XTAL                             003D0900
  348. LINE_FREQ                        00000032
  349. CLOCKCYCLES_PER_INSTRUCTIONS     00000004
  350. IPHW                             00002710
  351. INSTRUCTIONCYCLES_PER_DELAYCYC   00000003
  352. DIMM_WAIT                        0000000A
  353. dimm                             0000000C
  354. dimm_counter                     0000000D
  355. wait_counter                     0000000E
  356. init                             00000000
  357. main_loop                        0000000D
  358. dimm_it                          0000001D
  359. dimm_loop                        0000001F
  360. wait                             00000026
  361. wait_loop                        00000028
  362. ignition_wait                    0000002B
  363. i_wait_loop                      0000002D
  364. wait_line_change                 00000030
  365. line_is_high                     00000032
  366. line_is_low                      00000035
  367.  
  368.  
  369. Used Defines
  370. -----------------------------------------
  371. IGNITION_PRESET                  128 
  372. POWER_LINE                       PORTA,3 
  373. DARKER                           PORTB,4 
  374. BRIGHTER                         PORTB,5 
  375. ELR                              PORTA,2 
  376. DIMM_MIN                         15 
  377. IGNITION_DELAY                   30 
  378.  
  379.  
  380. PROGRAM MEMORY USAGE TABLE:    '-' = not used  'X' = used
  381.  
  382. 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXX--------
  383. 0040 : ---------------- ---------------- ---------------- ----------------
  384. 0080 : ---------------- ---------------- ---------------- ----------------
  385. 00C0 : ---------------- ---------------- ---------------- ----------------
  386. 0100 : ---------------- ---------------- ---------------- ----------------
  387. 0140 : ---------------- ---------------- ---------------- ----------------
  388. 0180 : ---------------- ---------------- ---------------- ----------------
  389. 01C0 : ---------------- ---------------- ---------------- ----------------
  390. 0200 : ---------------- ---------------- ---------------- ----------------
  391. 0240 : ---------------- ---------------- ---------------- ----------------
  392. 0280 : ---------------- ---------------- ---------------- ----------------
  393. 02C0 : ---------------- ---------------- ---------------- ----------------
  394. 0300 : ---------------- ---------------- ---------------- ----------------
  395. 0340 : ---------------- ---------------- ---------------- ----------------
  396. 0380 : ---------------- ---------------- ---------------- ----------------
  397. 03C0 : ---------------- ---------------- ---------------- ----------------
  398.  
  399. Program Memory Words Used:  0056
  400. Program Memory Words Free:  0968
  401.  
  402. Errors: 0
  403.